package basis.第十四章;


import java.util.concurrent.TimeUnit;

class MyThread1 extends Thread{
    private int sleepTime;
    public MyThread1(int sleepTime,String threadName) {
        this.sleepTime = sleepTime;
        setName(threadName);
        start();
    }

    @Override
    public void run() {
        try {
            Thread.sleep(sleepTime);
            System.out.println(Thread.currentThread());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

class MyThread2 extends Thread{
    private MyThread1 myThread1;
    public MyThread2(MyThread1 myThread1,String threadName) {
        this.myThread1 = myThread1;
        setName(threadName);
        start();
    }

    @Override
    public void run() {
        try {
            myThread1.join();
            System.out.println(Thread.currentThread());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

public class Example21211 {
    public static void main(String[] args) throws InterruptedException {
        MyThread1 myThread1 = new MyThread1(5000,"libai");
        MyThread2 liuming = new MyThread2(myThread1, "liuming");


    }
}
